<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layui/css/formSelects-v4.css" media="all">
    <link rel="shortcut icon" href="../../statics/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../../statics/css/font.css">
    <link rel="stylesheet" href="../../statics/css/xadmin.css">
    <script src="../../statics/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../statics/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../statics/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form" lay-filter="userModifyForm">
        <div class="layui-form-item" style="display: none">
            <label for="id" class="layui-form-label">
                <span class="x-red">*</span>id
            </label>
            <div class="layui-input-inline">
                <input type="text" id="id" name="id" required
                       autocomplete="off" value="" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="goodsName" class="layui-form-label">
                <span class="x-red">*</span>物品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="goodsName" name="goodsName"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label for="goodsDesc" class="layui-form-label">
                物品描述
            </label>
            <div class="layui-input-inline">
                <input type="text" value="" id="goodsDesc" name="goodsDesc"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>物品种类
            </label>
            <div class="layui-input-inline">
                <select name="kindsName" id="kindsNameId">
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="goodsNo" class="layui-form-label">
                <span class="x-red">*</span>物品编号
            </label>
            <div class="layui-input-inline">
                <input type="text" value="" id="goodsNo" name="goodsNo"
                       autocomplete="off" class="layui-input ">
            </div>
        </div>
  <!--
        <div class="layui-form-item">
        <label class="layui-form-label">物品状态</label>
        <div class="layui-input-block">
            <input type="radio" class="radioClass" name="goodsState" value="在库" title="在库">
            <input type="radio" class="radioClass" name="goodsState" value="不在库" title="不在库">
        </div>
        </div>
    -->

        <div class="layui-form-item">
            <label for="goodsPosition" class="layui-form-label">
                <span class="x-red">*</span>物品位置
            </label>
            <div class="layui-input-inline">
                <input type="text" value="" id="goodsPosition" name="goodsPosition"
                       autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="modify" lay-submit="">
                提交修改
            </button>
        </div>
    </form>
</div>
<script>

    var form ;
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        form = layui.form;
        var layer = layui.layer;
        $.post("/kinds/getAllKinds", function (result) {
            if (result.code === 0) {
                var select = document.getElementById("kindsNameId");
                for (var i = 0; i < result.data.length; i++) {
                    var option = document.createElement("option");
                    option.value = result.data[i].id;
                    option.text = result.data[i].kindsName;
                    select.appendChild(option);
                }
                form.render('select');
            }
        });
        //自定义验证规则
        form.verify({
            number: [/^\d{6,}$/, '学号格式为全数字或学号位数有误']
        });

        //监听提交
        form.on('submit(modify)', function (data) {
            console.log(data);
            debugger;
            $.ajax({
                url: "/goods/commitGoodsModifyInfo",
                data: {
                    id: data.field.id,
                    goodsName: data.field.goodsName,
                    goodsDesc: data.field.goodsDesc,
                    kindsId: data.field.kindsName,
                    goodsNo: data.field.goodsNo,
                    goodsPosition:data.field.goodsPosition
                },
                success:function (result) {
                    if(0===result.code){
                        layer.msg(result.msg, {icon: 6,time:500},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(result.msg, {icon: 5, time: 1000});
                    }
                }
            });
            return false;
        });
    });


    //等待父页面将id付给子页面的id标签value中
    setTimeout(function () {
        var id = $("#id").val();
        $.ajax({
            url: "/goods/getKindsNameByGoodsId",
            data: {
                goodsId: id
            },
            success: function (result) {
                debugger;
                var select1 = document.getElementById("kindsNameId");
                for (var i = 0; i < select1.length; i++) {
                    if (select1[i].innerText == result.data) {
                        select1[i].selected=true;
                        break;
                    }
                }
                form.render('select');
                form.render('radio');
            }
        });
    }, 200);

</script>


</body>

</html>